package com.jt.consumer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class ConsumerController {
    @Autowired
    private RestTemplate restTemplate;
    @Value("${server.port:8080}")
    private String serverPort;
    @GetMapping("/consumer/doRestEcho1")
    public String doRestEcho01(){
        String url="http://localhost:8081/provider/echo/http";
        return restTemplate.getForObject(url,String.class);
    }
    @Autowired
private LoadBalancerClient loadBalancerClient;
    @Autowired
    private RestTemplate LoadBalancedRestTemplate;

    @GetMapping("/consumer/doRestEcho2")
    public String doRestEcho02(){
        String url = "http://sca-provider/provider/echo/{msg}";
        url = String.format(url,String.class,serverPort);
        return LoadBalancedRestTemplate.getForObject(url,String.class,serverPort);
    }
}
